/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.shop.web;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.shop.entity.Goods;
import com.thinkgem.jeesite.modules.shop.entity.Order;
import com.thinkgem.jeesite.modules.shop.service.GoodsService;
import com.thinkgem.jeesite.modules.shop.service.OrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 商品信息Controller
 * @author dby
 * @version 2020-06-30
 */
@Controller
@RequestMapping(value = "${adminPath}/shop")
public class ShopController extends BaseController {

	@Autowired
	private GoodsService goodsService;

	@Autowired
	private OrderService orderService;

	/*
	 * @Author Zhang Xingliang
	 * @Description 商城首页
	 * @Date 0:12 2020/7/1
	 * @Param [goods, request, response, model]
	 * @return java.lang.String
	 **/
	@RequestMapping(value = {"index", ""})
	public String index(Goods goods, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<Goods> page = goodsService.findPage(new Page<Goods>(request, response), goods);
		model.addAttribute("page", page);
		return "modules/shop/index";
	}

	/*
	 * @Author Zhang Xingliang
	 * @Description 我的订单列表
	 * @Date 23:43 2020/6/30
	 * @Param [order, request, response, model]
	 * @return java.lang.String
	 **/
	@RequestMapping(value = {"myOrderList", ""})
	public String myOrderList(Order order, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<Order> page = orderService.findPage(new Page<Order>(request, response), order);
		model.addAttribute("page", page);
		return "modules/shop/myOrderList";
	}

	/*
	 * @Author Zhang Xingliang
	 * @Description 商品查看页面
	 * @Date 0:27 2020/7/1
	 **/
	@RequiresPermissions("shop:goods:view")
	@RequestMapping(value = "detail")
	public String view(Goods goods, Model model) {
		model.addAttribute("goods", goods);
		return "modules/shop/goodsView";
	}

}